package cn.kgc.shiroday03.controller;

import cn.kgc.shiroday03.commons.CodeMsg;
import cn.kgc.shiroday03.commons.ResponseResult;
import cn.kgc.shiroday03.dto.RolePageDTO;
import cn.kgc.shiroday03.entity.Role;
import cn.kgc.shiroday03.service.RoleService;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @Author: 课工场
 * @Version: v1.0  2023/6/6
 * @Description:
 */
@RestController
@RequestMapping("role")
@Api(tags = "角色模块")
public class RoleController {

    @Autowired
    private RoleService roleService;




    @GetMapping("xmselect")
    public ResponseResult getXmselectData() {
        List<Role> list = roleService.list();
        return new ResponseResult(CodeMsg.SUCCESS, null, list);
    }

    @GetMapping("page")
    public ResponseResult getRolePage(RolePageDTO rolePageDTO) {

        return roleService.getRolePage(rolePageDTO);
    }

    // 更新角色
    @PostMapping("saveOrUpdate")
    public ResponseResult saveOrUpdateRole(Role role) {
        return roleService.saveOrUpdateRole(role);
    }

    //根据id  查询角色信息
    @GetMapping("selectById")
    public ResponseResult selectById(Integer id) {

        Role role = roleService.getById(id);

        return new ResponseResult(CodeMsg.SUCCESS, null, role);

    }

    //根据id 删除角色信息
    @GetMapping("deleteById")
    public ResponseResult deleteById(String ids) {

          return roleService.deleteById(ids);
    }

    @GetMapping("selectPermissionByRoleId")
    public ResponseResult  selectPermissionByRoleId(Integer roleId){

       return roleService.selectPermissionByRoleId(roleId);

    }


    //addRolePermission

    @PostMapping("addRolePermission")
    public ResponseResult addRolePermission(Integer roleId,String permissionIds){

        return   roleService.addRolePermission(roleId,permissionIds);
    }

}
